import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// import visualizer from 'vite-plugin-visualizer'
// 引入插件
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// import ElementPlus from 'unplugin-element-plus/vite'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd())
    console.log('env', env) // 打印加载的环境变量
    return {
        NODE_ENV: 'production',
        plugins: [
            vue(),
            createSvgIconsPlugin({
                iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
                symbolId: 'icon-[dir]-[name]',
            }),
            viteMockServe({
                mockPath: 'mock',
                // localEnabled: true,
            }),
            // visualizer(),
        ],
        resolve: {
            alias: {
                '@': path.resolve('./src'),
            },
        },
        css: {
            preprocessorOptions: {
                scss: {
                    javascriptEnabled: true,
                    additionalData: `
                    @use "@/styles/variable.scss" as *;
                    @use "@/styles/element/index.scss" as *;
                    `,
                },
            },
        },
        server: {
            proxy: {
                '/api/admin/acl': {
                    // 更新代理规则以匹配新的路径
                    target: 'http://sph-api.atguigu.cn', // 目标后端服务
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ''),
                },
                '/api': {
                    //获取数据的服务器地址设置
                    target: 'http://39.98.123.211:8510',
                    //需要代理跨域
                    changeOrigin: true,
                    //路径重写
                    rewrite: (path) => path.replace(/^\/api/, ''),
                },
            },
        },
    }
})
